//package com.zmn.plat.dubbo.impl.channel;
//
//import com.alibaba.fastjson.JSONObject;
//import com.zmn.common.constant.GlobalConsts;
//import com.zmn.common.dto.VtDTO;
//import com.zmn.common.dto2.ResponseDTO;
//import com.zmn.common.utils.collection.CollectionUtil;
//import com.zmn.common.utils.number.NumberUtil;
//import com.zmn.common.utils.reflect.BeanMapper;
//import com.zmn.common.utils.string.StringUtil;
//import com.zmn.gateway.dubbo.client.GUserHolder;
//import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
//import com.zmn.manager.redis.lock.DistributedLock;
//import com.zmn.manager.redis.lock.DistributedLockUtils;
//import com.zmn.plat.business.interfaces.channel.ChannelBService;
//import com.zmn.plat.business.interfaces.channel.ChannelCategBService;
//import com.zmn.plat.business.interfaces.channel.ChannelServiceCategoryBService;
//import com.zmn.plat.common.constant.ProductConsts;
//import com.zmn.plat.common.constant.RedisKeyConstant;
//import com.zmn.plat.common.dictionary.PlatErrorCodeDict;
//import com.zmn.plat.common.dto.area.AreaSimpleDRO;
//import com.zmn.plat.common.dto.channel.*;
//import com.zmn.plat.common.exception.PlatException;
//import com.zmn.plat.dubbo.interfaces.channel.ChannelListRemoteService;
//import com.zmn.plat.dubbo.utils.DubboConsts;
//import com.zmn.plat.manager.dictionary.ChannelDict;
//import com.zmn.plat.model.entity.category.ServCategAndCategTwoQuery;
//import com.zmn.plat.model.entity.channel.*;
//import com.zmn.plat.model.entity.channel.bail.ChannelBail;
//import com.zmn.plat.model.entity.product.ServProduct;
//import com.zmn.plat.model.vo.channel.ChannelCountVo;
//import com.zmn.plat.persistence.interfaces.channel.ChannelDAO;
//import com.zmn.plat.services.interfaces.channel.*;
//import com.zmn.plat.services.interfaces.channel.bail.ChannelBailService;
//import com.zmn.plat.services.interfaces.product.ServProductService;
//import com.zmn.plat.utils.bean.BeanCopyUtils;
//import lombok.extern.log4j.Log4j2;
//import org.apache.dubbo.config.annotation.Service;
//import org.springframework.cache.annotation.Cacheable;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.util.CollectionUtils;
//
//import javax.annotation.Resource;
//import javax.validation.constraints.NotEmpty;
//import javax.validation.constraints.NotNull;
//import javax.validation.constraints.Positive;
//import java.util.*;
//import java.util.concurrent.TimeUnit;
//import java.util.stream.Collectors;
//
//@Log4j2
//@Service(version = DubboConsts.INTERFACE_VERSION, validation = "true")
//public class ChannelListRemoteServiceImpl implements ChannelListRemoteService {
//
//    @Resource
//    private ChannelService channelService;
//    @Resource
//    private ChannelDAO channelDAO;
//    @Resource
//    private ChannelBService channelBService;
//    @Resource
//    private ChannelCommissionService commissionService;
//    @Resource
//    private ChannelSettleService settleService;
//    @Resource
//    private ChannelDepositService depositService;
//    @Resource
//    private ChannelServiceAreaService channelServiceAreaService;
//    @Resource
//    ChannelServiceAreaCategoryService serviceAreaCategoryService;
//    @Resource
//    ChannelCategBService channelCategBService;
//    @Resource
//    ChannelServiceCategoryService categoryService;
//    @Resource
//    ServProductService servProductService;
//    @Resource
//    ChannelServiceCategoryBService channelServiceCategoryBService;
//    @Resource
//    ChannelBailService bailService;
//
//    @Resource
//    private RedisTemplate<String, String> redisTemplate;
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<ChannelDRO> getByChannelId(Integer channelId) {
//
//        log.info("ChannelListRemoteServiceImpl.getByChannelId参数channelId：{}", channelId);
//        try {
//            ChannelDRO channelDRO = channelBService.getByChannelId(channelId);
//            return ResponseDTO.success(channelDRO);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelDRO>> listByChannelIds(List<Integer> channelIds) {
//        log.info("ChannelListRemoteServiceImpl.listByChannelIds参数channelIds：{}", channelIds);
//        if (CollectionUtils.isEmpty(channelIds)) {
//            return ResponseDTO.fail("渠道ID不能为空");
//        }
//        try {
//            ChannelQuery query = new ChannelQuery();
//            query.setChannelIds(channelIds);
//            List<Channel> channels = channelService.listByQuery(query);
//            List<ChannelDRO> channelDROS = BeanMapper.mapList(channels, ChannelDRO.class);
//            return ResponseDTO.success(channelDROS);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelDRO>> listByCompanyId(Integer companyId) {
//        log.info("ChannelListRemoteServiceImpl.listByCompanyId参数companyId：{}", companyId);
//        if (Objects.isNull(companyId)) {
//            return ResponseDTO.fail("公司ID不能为空");
//        }
//        try {
//            ChannelQuery query = new ChannelQuery();
//            query.setCompanyId(companyId);
//            List<Channel> channels = channelService.listByQuery(query);
//            List<ChannelDRO> channelDROS = BeanMapper.mapList(channels, ChannelDRO.class);
//            return ResponseDTO.success(channelDROS);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listVtByChannelAnotherName(String anotherName) {
//        try {
//            List<VtDTO> channels = channelService.listVtByChannelAnotherName(anotherName);
//            return ResponseDTO.success(channels);
//        } catch (RuntimeException e) {
//            return ResponseDTO.fail(e.getMessage());
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listVtByParentIds(List<Integer> parentIds, Integer status) {
//
//        if (CollectionUtils.isEmpty(parentIds)) {
//            return ResponseDTO.fail("父级渠道id集合不能为空");
//        }
//        try {
//            ChannelQuery query = new ChannelQuery();
//            query.setParentIds(parentIds);
//            query.setStatus(status);
//            List<VtDTO> channelVts = Optional.ofNullable(channelService.listByQuery(query))
//                    .orElse(Collections.emptyList())
//                    .stream()
//                    .map(mm -> {
//                        return new VtDTO(mm.getChannelId(), mm.getName(), mm.getStatus());
//                    })
//                    .collect(Collectors.toList());
//            return ResponseDTO.success(channelVts);
//        } catch (Exception e) {
//            log.error("ChannelListRemoteServiceImpl.listVtByParentIds查询失败,原因:{}", e.getMessage(), e);
//            return ResponseDTO.fail("查询失败，程序异常");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelDRO>> listByDIO(ChannelDIO channelDIO) {
//        log.info("ChannelListRemoteServiceImpl.listByDIO参数channelDIO：{}", channelDIO);
//
//        try {
//            ChannelQuery query = new ChannelQuery();
//            BeanCopyUtils.copyProperties(channelDIO, query);
//
//            Integer staffId = null;
//            if (channelDIO.getLimitPermit() != null && channelDIO.getLimitPermit()) {
//                // 过滤数据权限
//                staffId = GUserHolder.getCurrentLoginStaffId();
//                if (NumberUtil.isNullOrZero(staffId)) {
//                    return ResponseDTO.fail("身份校验失败");
//                }
//            }
//
//            // 忽略数据权限过滤
//            if (NumberUtil.isNotNullOrZero(staffId)) {
//                query.setOperatorId(staffId);
//            }
//
//            List<Channel> channels = channelService.listByQuery(query);
//            List<ChannelDRO> channelDROS = BeanMapper.mapList(channels, ChannelDRO.class);
//            if (CollectionUtil.isNullOrEmpty(channelDROS)) {
//                return ResponseDTO.success(Collections.EMPTY_LIST);
//            }
//
//            return ResponseDTO.success(channelDROS);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelCountDRO>> listCountByStatusAndChannelIdsGroupByParentId(List<Integer> channelIds, Integer status) {
//        log.info("listCountByStatusAndChannelIdsGroupByParentId参数channelIds：{},status:{}", channelIds, status);
//        List<ChannelCountVo> channels = channelService.listCountByStatusAndChannelIdsGroupByParentId(channelIds, status);
//        List<ChannelCountDRO> list = new ArrayList<>();
//        if (!CollectionUtils.isEmpty(channels)) {
//            list = BeanCopyUtils.copyProperties(channels, ChannelCountVo.class, ChannelCountDRO.class, ChannelCountDRO::new);
//        }
//        return ResponseDTO.success(list);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelSimpleDRO>> listByChannelOrderConfigDIO(ChannelOrderConfigDIO channelOrderConfigDIO) {
//        log.info("ChannelListRemoteServiceImpl.listByChannelOrderConfigDIO参数channelOrderConfigDIO：{}", channelOrderConfigDIO);
//
//        if (Objects.isNull(channelOrderConfigDIO)) {
//            log.error("参数不能为空");
//            return ResponseDTO.fail("参数不能为空");
//        }
//
//        ChannelCombinationQuery query = new ChannelCombinationQuery();
//        BeanCopyUtils.copyProperties(channelOrderConfigDIO, query);
//        List<ChannelSimpleVO> result = channelService.listByCombinationQuery(query);
//        List<ChannelSimpleDRO> dros = BeanMapper.mapList(result, ChannelSimpleDRO.class);
//
//        return ResponseDTO.success(dros);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listVtByAppliqueAndRank(Integer applique, Integer rank) {
//        log.info("ChannelListRemoteServiceImpl.listVtByApplique参数applique：{}，rank：{}", applique, rank);
//
//        if (NumberUtil.isNullOrZero(applique)) {
//            return ResponseDTO.fail("是否允许贴花参数不能为空");
//        }
//
//        if (NumberUtil.isNullOrZero(rank)) {
//            return ResponseDTO.fail("渠道层级不能为空");
//        }
//
//        List<VtDTO> result = channelService.listVtByAppliqueAndRank(applique, rank);
//
//        if (CollectionUtil.isNotNullOrEmpty(result)) {
//            return ResponseDTO.success(result);
//        }
//
//        return ResponseDTO.success(Collections.EMPTY_LIST);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<AreaSimpleDRO>> listAreaByChannelId(Integer channelId) {
//        log.info("ChannelListRemoteServiceImpl.listAreaByChannelId参数channelId：{}", channelId);
//        try {
//            List<AreaSimpleDRO> dros = channelBService.listAreaByChannelId(channelId);
//            return ResponseDTO.success(dros);
//        } catch (PlatException e) {
//            return ResponseDTO.fromErrorCodeTable(e.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    public ResponseDTO<Boolean> checkOpenServ(Integer channelId, Integer cityId, Integer productId) {
//
//        if (NumberUtil.isNullOrZero(channelId) || NumberUtil.isNullOrZero(cityId) || NumberUtil.isNullOrZero(productId)) {
//            return ResponseDTO.fail("参数不合法");
//        }
//        try {
//            // 查询产品
//            ServProduct product = servProductService.findByKey(productId);
//            if (Objects.isNull(product)) {
//                return ResponseDTO.fail("产品不存在");
//            }
//
//            // 判断渠道是否开通分类，如果已开通则取当前渠道，反之取上级渠道信息
//            channelId = channelServiceCategoryBService.getAvailableCategoryChannelId(channelId);
//            if (NumberUtil.isNullOrZero(channelId)) {
//                return ResponseDTO.fail("渠道不可用");
//            }
//
//            List<ServCategAndCategTwoQuery> channelServiceAreaServList;
//            // 渠道开通的区域
//            List<ChannelServiceArea> channelAreas = channelServiceAreaService.listByChannelId(channelId);
//            if (CollectionUtils.isEmpty(channelAreas)) {
//                // 未开通任何区域，表示开通所有
//                channelServiceAreaServList = categoryService.listServCategAndCategTwoQueryByChannelIdAndShowType(channelId, ProductConsts.EC_PRODUCT_TYPE);
//            } else {
//                // 开通城市集合
//                List<Integer> cityIdList = channelAreas.stream().map(ChannelServiceArea::getCityId).collect(Collectors.toList());
//                // 未开通该城市
//                if (!cityIdList.contains(cityId)) {
//                    return ResponseDTO.success(false, "很抱歉，您的地址不在服务区域内");
//                }
//                // 渠道开通的区域的服务分类
//                channelServiceAreaServList = serviceAreaCategoryService.listServCategAndCategTwoQueryByChannelIdAndCityIdAndShowType(channelId, cityId, ProductConsts.EC_PRODUCT_TYPE);
//                if (CollectionUtils.isEmpty(channelServiceAreaServList)) {
//                    // 区域未开通任何分类，表示开通所有
//                    channelServiceAreaServList = categoryService.listServCategAndCategTwoQueryByChannelIdAndShowType(channelId, ProductConsts.EC_PRODUCT_TYPE);
//                }
//            }
//            // 匹配分类
//            if (!CollectionUtils.isEmpty(channelServiceAreaServList)) {
//                for (ServCategAndCategTwoQuery servCateg : channelServiceAreaServList) {
//                    if (Objects.equals(servCateg.getServCategId(), product.getServCategId()) &&
//                            Objects.equals(servCateg.getCategOneId(), product.getCategOneId()) &&
//                            Objects.equals(servCateg.getCategTwoId(), product.getCategId())) {
//                        return ResponseDTO.success(true);
//                    }
//                }
//            }
//            return ResponseDTO.success(false, "很抱歉，您的地址暂不支持该服务品类");
//        } catch (Exception e) {
//            log.error("ChannelListRemoteServiceImpl.checkCityByChannelId查询失败,原因:{}", e.getMessage(), e);
//            return ResponseDTO.fail("查询失败，程序异常");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<ChannelListPageDRO> listPageByDIO(ChannelDIO channelDIO) {
//        log.info("ChannelListRemoteServiceImpl.listPageByDIO参数channelDIO：{}", channelDIO);
//
//        try {
//            ChannelListPageDRO dro = new ChannelListPageDRO();
//            ChannelQuery query = new ChannelQuery();
//            BeanCopyUtils.copyProperties(channelDIO, query);
//            Integer totalCount = channelService.countByQuery(query);
//            if (totalCount > 0) {
//                List<Channel> channels = channelService.listPageByQuery(query, null);
//                List<ChannelDRO> dros = BeanMapper.mapList(channels, ChannelDRO.class);
//                dro.setItems(dros);
//            } else {
//                dro.setItems(Collections.EMPTY_LIST);
//            }
//            dro.setTotalCount(totalCount);
//            return ResponseDTO.success(dro);
//        } catch (Exception e) {
//            log.error("系统错误! 调用失败!, exception:{}, msg:{}", e, e.getMessage());
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:all'", cacheNames = "redis5m")
//    public ResponseDTO<List<ChannelDRO>> listAll() {
//        try {
//            List<Channel> channels = channelService.listByQuery(null);
//            List<ChannelDRO> channelDROS = BeanMapper.mapList(channels, ChannelDRO.class);
//            return ResponseDTO.success(channelDROS);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:twolevel:plat:'+#p0+'type:'+#p1", cacheNames = "redis5m")
//    public ResponseDTO<List<ChannelDRO>> listTwoLevelChannel(Integer plat, Integer channelType) {
//        log.info("ChannelListRemoteServiceImpl.listTwoLevelChannel参数plat：{}，channelType：{}", plat, channelType);
//
//        try {
//            List<Channel> channels = channelService.listTwoLevelChannel(plat, channelType);
//            List<ChannelDRO> channelDROS = BeanMapper.mapList(channels, ChannelDRO.class);
//            return ResponseDTO.success(channelDROS);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<VtDTO>> listTwoLevelChannelVtByPlatAndChannelType(Integer plat, Integer channelType) {
//        log.info("ChannelListRemoteServiceImpl.listTwoLevelChannelVtByPlatAndChannelType参数plat：{}，channelType：{}", plat, channelType);
//
//        try {
//            List<Channel> channels = channelDAO.listTwoLevelChannelVt(plat, channelType);
//            List<VtDTO> dtos = channels.stream().map(e -> new VtDTO(e.getChannelId(), e.getName())).collect(Collectors.toList());
//            return ResponseDTO.success(dtos);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelDRO>> listChannelByNotCps(Integer plat, Integer channelType) {
//        log.info("ChannelListRemoteServiceImpl.listChannelByNotCps参数plat：{}，channelType：{}", plat, channelType);
//
//        try {
//            List<Channel> channels = channelService.listChannelByNotCps(plat, channelType);
//            List<ChannelDRO> channelDROS = BeanMapper.mapList(channels, ChannelDRO.class);
//            return ResponseDTO.success(channelDROS);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelDRO>> listByParentId(Integer parentId) {
//
//        log.info("ChannelListRemoteServiceImpl.listChannelByNotCps参数parentId：{}", parentId);
//        if (NumberUtil.isNullOrZero(parentId)) {
//            return ResponseDTO.fail("渠道父ID不能为空");
//        }
//        String key = RedisKeyConstant.getKeyParentChannelDro(parentId);
//        String value = redisTemplate.opsForValue().get(key);
//        // 缓存中有数据
//        if (StringUtil.isNotBlank(value)) {
//            if (RedisKeyConstant.NO_DATA.equals(value)) {
//                return ResponseDTO.success();
//            } else {
//                List<ChannelDRO> channelList = JSONObject.parseArray(value, ChannelDRO.class);
//                return ResponseDTO.success(channelList);
//            }
//        }
//        int time = 60;
//        String lockKey = RedisKeyConstant.getLockKeyParentChannelDro(parentId);
//        DistributedLock redisLock = DistributedLockUtils.buildReentrantLock(lockKey, time);
//        if (redisLock.tryLock()) {
//            try {
//                ChannelQuery query = new ChannelQuery();
//                query.setParentId(parentId);
//                List<Channel> channels = channelService.listByQuery(query);
//                List<ChannelDRO> channelList = BeanMapper.mapList(channels, ChannelDRO.class);
//                if (channelList == null || channelList.size() == 0) {
//                    value = RedisKeyConstant.NO_DATA;
//                } else {
//                    value = JSONObject.toJSONString(channelList);
//                }
//                redisTemplate.opsForValue().set(key, value, 5, TimeUnit.MINUTES);
//                return ResponseDTO.success(channelList);
//            } catch (Exception e) {
//                log.error("error：", e);
//                return ResponseDTO.fail("系统错误! 调用失败!");
//            } finally {
//                try {
//                    redisLock.unlock();
//                } catch (Exception ignored) {
//                }
//            }
//        } else {
//            if (redisLock.lock(time, TimeUnit.SECONDS)) {
//                try {
//                    redisLock.unlock();
//                } catch (Exception ignored) {
//                }
//                return listByParentId(parentId);
//            } else {
//                log.error("获取渠道信息，获取redis锁超时");
//                return ResponseDTO.fail("系统错误! 获取redis锁超时!");
//            }
//        }
//    }
//
//    // @Override
//    // @ReadOnlyConnection
//    // @Cacheable(key = "'dubbo:list:channel:platform:type:ids:'+#p0", cacheNames = "redis5m")
//    // public ResponseDTO<List<ChannelPlatformTypeDRO>> listPlatformTypeByChannelIds(List<Integer> channelIds) {
//    // log.info("ChannelListRemoteServiceImpl.listPlatformTypeByChannelIds参数channelIds：{}", channelIds);
//    //
//    // if (CollectionUtil.isNullOrEmpty(channelIds)) {
//    // return ResponseDTO.fail("渠道ID不能为空");
//    // }
//    //
//    // try {
//    // ChannelQuery query = new ChannelQuery();
//    // query.setChannelIds(channelIds);
//    // List<ChannelVO> channels = channelService.listChannelVoByQuery(query);
//    // List<ChannelPlatformTypeDRO> dros = BeanMapper.mapList(channels, ChannelPlatformTypeDRO.class);
//    // return ResponseDTO.success(dros);
//    // } catch (Exception e) {
//    // log.error("error：", e);
//    // return ResponseDTO.fail("系统错误! 调用失败!");
//    // }
//    // }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<ChannelSettleDRO> getSettleByChannelId(Integer channelId) {
//
//        log.info("ChannelListRemoteServiceImpl.getSettleByChannelId参数channelId：{}", channelId);
//        if (Objects.isNull(channelId)) {
//            return ResponseDTO.fail("渠道ID不能为空");
//        }
//        String key = RedisKeyConstant.getKeyChannelSettleDro(channelId);
//        String value = redisTemplate.opsForValue().get(key);
//        // 缓存中有数据
//        if (StringUtil.isNotBlank(value)) {
//            try {
//                ChannelSettleDRO settle = JSONObject.parseObject(value, ChannelSettleDRO.class);
//                return ResponseDTO.success(settle);
//            } catch (Exception e) {
//                return ResponseDTO.fail(value);
//            }
//        }
//        int time = 60;
//        String lockKey = RedisKeyConstant.getLockKeyChannelSettleDro(channelId);
//        DistributedLock redisLock = DistributedLockUtils.buildReentrantLock(lockKey, time);
//        if (redisLock.tryLock()) {
//            try {
//                ResponseDTO<ChannelSettleDRO> response = getSettleByChannelIdDataBase(channelId);
//                if (response.isSuccess()) {
//                    value = JSONObject.toJSONString(response.getData());
//                } else {
//                    value = response.getMessage();
//                }
//                redisTemplate.opsForValue().set(key, value, 5, TimeUnit.MINUTES);
//                return response;
//            } finally {
//                try {
//                    redisLock.unlock();
//                } catch (Exception ignored) {
//                }
//            }
//        } else {
//            if (redisLock.lock(time, TimeUnit.SECONDS)) {
//                try {
//                    redisLock.unlock();
//                } catch (Exception ignored) {
//                }
//                return getSettleByChannelId(channelId);
//            } else {
//                log.error("根据渠道ID查询渠道订单配置，获取redis锁超时");
//                return ResponseDTO.fail("根据渠道ID查询渠道订单配置，获取redis锁超时");
//            }
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<ChannelSettleErpDRO> getSettleAccountByChannelId(Integer channelId) {
//
//        log.info("ChannelListRemoteServiceImpl.getSettleAccountByChannelId参数channelId：{}", channelId);
//        if (NumberUtil.isNullOrZero(channelId)) {
//            return ResponseDTO.fail("渠道ID不能为空");
//        }
//        // 查询渠道基本信息
//        try {
//            Channel channel = channelService.findByKey(channelId);
//            if (Objects.isNull(channel)) {
//                return ResponseDTO.fail("渠道不存在");
//            }
//            // 查询渠道结算信息
//            ChannelSettle settle = Optional.ofNullable(settleService.findByKey(channelId)).orElseGet(ChannelSettle::new);
//            ChannelSettleErpDRO dro = ChannelSettleErpDRO.builder()
//                    .channelId(channel.getChannelId())
//                    .name(channel.getName())
//                    .cityId(channel.getCityId())
//                    .accountName(settle.getAccountName())
//                    .bankAccount(settle.getBankAccount())
//                    .bankBranch(settle.getBankBranch())
//                    .build();
//            return ResponseDTO.success(dro);
//        } catch (Exception e) {
//            log.error("ChannelListRemoteServiceImpl.getSettleAccountByChannelId查询失败,原因:{}", e.getMessage(), e);
//            return ResponseDTO.fail("查询失败，程序异常");
//        }
//    }
//
//    private ResponseDTO<ChannelSettleDRO> getSettleByChannelIdDataBase(Integer channelId) {
//        try {
//            ChannelSettle settle = settleService.findByKey(channelId);
//            ChannelSettleDRO dro;
//            // 如果有配置则直接返回
//            if (!Objects.isNull(settle)) {
//                dro = BeanMapper.map(settle, ChannelSettleDRO.class);
//                return ResponseDTO.success(dro);
//            }
//            Channel channel = channelService.findByKey(channelId);
//            if (Objects.isNull(channel)) {
//                return ResponseDTO.fail("渠道不存在");
//            }
//            if (ChannelDict.RANK_ONE == channel.getRank() || null == channel.getParentId()) {
//                return ResponseDTO.fail("找不到渠道对应配置");
//            }
//            settle = settleService.findByKey(channel.getParentId());
//            if (Objects.isNull(settle)) {
//                return ResponseDTO.fail("找不到渠道对应配置");
//            }
//            dro = BeanMapper.map(settle, ChannelSettleDRO.class);
//            return ResponseDTO.success(dro);
//
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    @Cacheable(key = "'dubbo:list:channel:settle:all'", cacheNames = "redis5m")
//    public ResponseDTO<List<ChannelSettleDRO>> listSettleAll() {
//        try {
//            List<ChannelSettle> settles = settleService.listAll();
//            List<ChannelSettleDRO> dro = BeanMapper.mapList(settles, ChannelSettleDRO.class);
//            return ResponseDTO.success(dro);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<Boolean> checkNotifyEngineer(@NotNull(message = "channelId不能为空") @Positive(message = "channelId必须为大于0的正整数") Integer channelId) {
//        log.info("checkNotifyEngineer参数channelId：{}", channelId);
//        try {
//            boolean flag = channelBService.checkNotifyEngineer(channelId);
//            return ResponseDTO.success(flag);
//        } catch (PlatException ex) {
//            return ResponseDTO.fromErrorCodeTable(ex.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<Boolean> checkShowOrderPrice(@NotNull(message = "channelId不能为空") @Positive(message = "channelId必须为大于0的正整数") Integer channelId) {
//        log.info("checkNotifyEngineer参数channelId：{}", channelId);
//        try {
//            boolean flag = channelBService.checkShowOrderPrice(channelId);
//            return ResponseDTO.success(flag);
//        } catch (PlatException ex) {
//            return ResponseDTO.fromErrorCodeTable(ex.getErrorCode());
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List<ChannelSettleDRO>> listSettleByNotCps() {
//        try {
//            List<ChannelSettle> settles = settleService.listByNotCps();
//            List<ChannelSettleDRO> dro = BeanMapper.mapList(settles, ChannelSettleDRO.class);
//            return ResponseDTO.success(dro);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<Integer> getDepositByChannelId(Integer channelId) {
//
//        log.info("ChannelListRemoteServiceImpl.getDepositByChannelId参数channelId：{}", channelId);
//        if (Objects.isNull(channelId)) {
//            return ResponseDTO.fail("渠道ID不能为空");
//        }
//        String key = RedisKeyConstant.getKeyChannelDeposit(channelId);
//        String value = redisTemplate.opsForValue().get(key);
//        // 缓存中有数据
//        if (StringUtil.isNotBlank(value)) {
//            Integer balance = Integer.parseInt(value);
//            return ResponseDTO.success(balance);
//        }
//        int time = 60;
//        String lockKey = RedisKeyConstant.getLockKeyChannelDeposit(channelId);
//        DistributedLock redisLock = DistributedLockUtils.buildReentrantLock(lockKey, time);
//        if (redisLock.tryLock()) {
//            try {
//                ChannelDeposit deposit = depositService.findByKey(channelId);
//                int balance = deposit == null ? 0 : deposit.getBalance();
//                redisTemplate.opsForValue().set(key, balance + "", 5, TimeUnit.MINUTES);
//                return ResponseDTO.success(balance);
//            } catch (Exception e) {
//                log.error("error：", e);
//                return ResponseDTO.fail("系统错误! 调用失败!");
//            } finally {
//                try {
//                    redisLock.unlock();
//                } catch (Exception ignored) {
//                }
//            }
//        } else {
//            if (redisLock.lock(time, TimeUnit.SECONDS)) {
//                try {
//                    redisLock.unlock();
//                } catch (Exception ignored) {
//                }
//                return getDepositByChannelId(channelId);
//            } else {
//                log.error("根据渠道id查询开通了分类的渠道id，获取redis锁超时");
//                throw new PlatException(PlatErrorCodeDict.ERROR_CODE_TIME_OUT);
//            }
//        }
//    }
//
//    @SuppressWarnings("Duplicates")
//    @ReadOnlyConnection
//    @Override
//    public ResponseDTO<Integer> getBailByChannelId(Integer channelId) {
//
//        log.info("ChannelListRemoteServiceImpl.getBailByChannelId参数channelId：{}", channelId);
//        if (Objects.isNull(channelId)) {
//            return ResponseDTO.fail("渠道ID不能为空");
//        }
//        String key = RedisKeyConstant.getKeyChannelBail(channelId);
//        String value = redisTemplate.opsForValue().get(key);
//        // 缓存中有数据
//        if (StringUtil.isNotBlank(value)) {
//            Integer balance = Integer.parseInt(value);
//            return ResponseDTO.success(balance);
//        }
//        int time = 60;
//        String lockKey = RedisKeyConstant.getLockKeyChannelBail(channelId);
//        DistributedLock redisLock = DistributedLockUtils.buildReentrantLock(lockKey, time);
//        if (redisLock.tryLock()) {
//            try {
//                ChannelBail bail = bailService.findById(channelId);
//                int balance = bail == null ? 0 : bail.getBalance();
//                redisTemplate.opsForValue().set(key, balance + "", 5, TimeUnit.MINUTES);
//                return ResponseDTO.success(balance);
//            } catch (Exception e) {
//                log.error("error：", e);
//                return ResponseDTO.fail("系统错误! 调用失败!");
//            } finally {
//                try {
//                    redisLock.unlock();
//                } catch (Exception ignored) {
//                }
//            }
//        } else {
//            if (redisLock.lock(time, TimeUnit.SECONDS)) {
//                try {
//                    redisLock.unlock();
//                } catch (Exception ignored) {
//                }
//                return getBailByChannelId(channelId);
//            } else {
//                log.error("根据渠道id查询保证金，获取redis锁超时");
//                throw new PlatException(PlatErrorCodeDict.ERROR_CODE_TIME_OUT);
//            }
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<ChannelProductDRO> getByServIdAndChannelId(Integer channelId, Integer plat, Integer servCategId) {
//        log.info("ChannelListRemoteServiceImpl.getByServIdAndChannelId参数channelId：{}，plat：{}，servCategId：{}", channelId, plat, servCategId);
//
//        if (Objects.isNull(channelId)) {
//            return ResponseDTO.fail("渠道ID不能为空");
//        }
//        if (Objects.isNull(servCategId)) {
//            return ResponseDTO.fail("服务分类ID不能为空");
//        }
//        try {
//            List<ChannelCommission> commissionList = commissionService.listByChannelId(channelId);
//            if (commissionList.isEmpty()) {
//                Channel channel = channelService.findByKey(channelId);
//                if (Objects.isNull(channel)) {
//                    return ResponseDTO.fail("渠道不存在");
//                }
//                if (ChannelDict.RANK_ONE == channel.getRank() || null == channel.getParentId()) {
//                    return ResponseDTO.fail("没有相关渠道服务分类信息");
//                }
//                commissionList = commissionService.listByChannelId(channel.getParentId());
//                if (commissionList.isEmpty()) {
//                    return ResponseDTO.fail("没有相关渠道服务分类信息");
//                }
//            }
//
//            ChannelProductDRO dro = new ChannelProductDRO();
//            ChannelCommission commission = commissionList.stream().filter(e -> servCategId.equals(e.getServCategId())).findAny().orElse(null);
//            if (Objects.isNull(commission)) {
//                return ResponseDTO.fail("没有相关渠道服务分类信息");
//            }
//
//            dro.setChannelId(commission.getChannelId());
//            dro.setCommission(commission.getCommissionCurrent().doubleValue());
//            dro.setCommissionType(commission.getCommissionType());
//            dro.setPlat(plat);
//            dro.setPriceDiscount(commission.getPriceDiscount());
//            dro.setServCategId(commission.getServCategId());
//            dro.setBaseType(commission.getBaseType());
//            return ResponseDTO.success(dro);
//        } catch (Exception e) {
//            log.error("error：", e);
//            return ResponseDTO.fail("系统错误! 调用失败!");
//        }
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public com.zmn.common.dto2.ResponseDTO<List> listChannelVtByQuery(Integer plat, Integer type, Integer centId, Integer deptId, Integer parentId, Integer status) {
//        return this.listChannelVtByQuery(plat, type, centId, deptId, parentId, status, null, false);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public com.zmn.common.dto2.ResponseDTO<List> listChannelVtByQuery(Integer plat, Integer type, Integer centId, Integer deptId, Integer parentId, Integer status, Boolean limitPermit) {
//        return this.listChannelVtByQuery(plat, type, centId, deptId, parentId, status, null, limitPermit);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public com.zmn.common.dto2.ResponseDTO<List> listChannelVtByQuery(Integer plat, Integer type, Integer centId, Integer deptId, Integer parentId, Integer status, Integer staffId) {
//        return this.listChannelVtByQuery(plat, type, centId, deptId, parentId, status, null, staffId);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public com.zmn.common.dto2.ResponseDTO<List> listChannelVtByQuery(Integer plat, Integer type, Integer centId, Integer deptId, Integer parentId, Integer status, String keyword) {
//        return listChannelVtByQuery(plat, type, centId, deptId, parentId, status, keyword, false);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public com.zmn.common.dto2.ResponseDTO<List> listChannelVtByQuery(Integer plat, Integer type, Integer centId, Integer deptId, Integer parentId, Integer status, String keyword,
//                                                                      Boolean limitPermit) {
//        Integer staffId = null;
//        if (limitPermit) {
//            staffId = GUserHolder.getCurrentLoginStaffId();
//            if (NumberUtil.isNullOrZero(staffId)) {
//                staffId = -1;
//            }
//        }
//        return listChannelVtByQuery(plat, type, centId, deptId, parentId, status, keyword, staffId);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public com.zmn.common.dto2.ResponseDTO<List> listChannelVtByQuery(Integer plat, Integer type, Integer centId, Integer deptId, Integer parentId, Integer status, String keyword, Integer staffId) {
//        return listChannelVtByQuery(plat, type, centId, deptId, parentId, status, keyword, staffId, false);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List> listChannelVtByQuery(Integer plat, Integer type, Integer centId, Integer deptId, Integer parentId, Integer status, String keyword, Boolean limitPermit,
//                                                  Boolean firstGetAnotherName) {
//        Integer staffId = null;
//        if (limitPermit) {
//            staffId = GUserHolder.getCurrentLoginStaffId();
//            if (NumberUtil.isNullOrZero(staffId)) {
//                staffId = -1;
//            }
//        }
//        return listChannelVtByQuery(plat, type, centId, deptId, parentId, status, keyword, staffId, firstGetAnotherName);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List> listChannelVtByQuery(Integer plat, Integer type, Integer centId, Integer deptId, Integer parentId, Integer status, String keyword, Integer staffId,
//                                                  Boolean firstGetAnotherName) {
//
//        // -1表示要求数据权限但未通过身份校验
//        if (NumberUtil.isNotNullOrZero(staffId) && staffId == -1) {
//            return com.zmn.common.dto2.ResponseDTO.fail("身份校验失败");
//        }
//
//        plat = NumberUtil.isNullOrZero(plat) ? null : plat;
//        type = NumberUtil.isNullOrZero(type) ? null : type;
//        centId = NumberUtil.isNullOrZero(centId) ? null : centId;
//        deptId = NumberUtil.isNullOrZero(deptId) ? null : deptId;
//        parentId = NumberUtil.isNullOrZero(parentId) ? null : parentId;
//        status = NumberUtil.isNullOrZero(status) ? null : status;
//        keyword = StringUtil.isBlank(keyword) ? null : keyword;
//
//        List<VtDTO> items = channelBService.listChannelVtByQuery(staffId, plat, type, centId, deptId, parentId, status, keyword).stream()
//                .map(p -> new VtDTO(p.getChannelId(), (firstGetAnotherName != null && firstGetAnotherName) && StringUtil.isNotBlank(p.getAnotherName()) ? p.getAnotherName() : p.getName(), p.getStatus()))
//                .collect(Collectors.toList());
//
//        if (CollectionUtil.isNullOrEmpty(items)) {
//            return com.zmn.common.dto2.ResponseDTO.success(Collections.EMPTY_LIST);
//        }
//
//        // 忽略数据权限过滤
//        return com.zmn.common.dto2.ResponseDTO.success(items);
//    }
//
//    @Override
//    @ReadOnlyConnection
//    public ResponseDTO<List> listChannelVtByQuery(ChannelSearchDIO channelSearchDIO, String keyword, Boolean limitPermit) {
//
//        Integer plat = channelSearchDIO.getPlat();
//        Integer centId = channelSearchDIO.getCentId();
//        Integer deptId = channelSearchDIO.getDeptId();
//        Integer parentId = channelSearchDIO.getParentId();
//        Integer status = channelSearchDIO.getStatus();
//        Integer type = channelSearchDIO.getType();
//        Integer rank = channelSearchDIO.getRank();
//        // 是否过滤数据权限，不传默认false
//        limitPermit = Optional.ofNullable(limitPermit).orElse(false);
//        // 优先获取渠道别名，不传默认false
//        Boolean firstGetAnotherName = Optional.ofNullable(channelSearchDIO.getFirstGetAnotherName()).orElse(false);
//
//        Integer staffId = channelSearchDIO.getStaffId();
//        // 过滤数据权限 且 未传入员工ID则自动获取
//        if (limitPermit && NumberUtil.isNullOrZero(staffId)) {
//            staffId = GUserHolder.getCurrentLoginStaffId();
//            if (NumberUtil.isNullOrZero(staffId)) {
//                return com.zmn.common.dto2.ResponseDTO.fail("身份校验失败");
//            }
//        }
//
//        plat = NumberUtil.isNullOrZero(plat) ? null : plat;
//        type = NumberUtil.isNullOrZero(type) ? null : type;
//        centId = NumberUtil.isNullOrZero(centId) ? null : centId;
//        deptId = NumberUtil.isNullOrZero(deptId) ? null : deptId;
//        parentId = NumberUtil.isNullOrZero(parentId) ? null : parentId;
//        status = NumberUtil.isNullOrZero(status) ? null : status;
//        keyword = StringUtil.isBlank(keyword) ? null : keyword;
//        rank = NumberUtil.isNullOrZero(rank) ? null : rank;
//
//        ChannelQuery query = new ChannelQuery();
//        query.setPlat(plat);
//        query.setChannelType(type);
//        query.setOneDeptId(centId);
//        query.setDeptId(deptId);
//        query.setParentId(parentId);
//        query.setStatus(status);
//        query.setLikeName(keyword);
//        query.setRank(rank);
//
//        // 忽略数据权限过滤
//        if (NumberUtil.isPositiveInteger(staffId) && limitPermit) {
//            query.setOperatorId(staffId);
//        }
//        List<Channel> channelList = channelService.listByQuery(query);
//
//        List<VtDTO> items = channelList.stream()
//                .map(p -> new VtDTO(p.getChannelId(), firstGetAnotherName && StringUtil.isNotBlank(p.getAnotherName()) ? p.getAnotherName() : p.getName(), p.getStatus())).collect(Collectors.toList());
//
//        if (CollectionUtil.isNullOrEmpty(items)) {
//            return com.zmn.common.dto2.ResponseDTO.success(Collections.EMPTY_LIST);
//        }
//
//        return com.zmn.common.dto2.ResponseDTO.success(items);
//    }
//
//}
